<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("编辑任务单")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript" src="/resources/js/reference/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/plugin/datePicker/WdatePicker.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<script src="/resources/js/base/file.js"></script>
<script type="text/javascript">
function editQty(t,e){
	extractNumber(t,0,false,e);
}
$().ready(function() {
	var $inputForm = $("#inputForm");
	var $addElock = $("#addElock");
	var $deleteElock = $("a.deleteElock");

	//打开选择锁界面
    $addElock.click(function(){
        $addElock.bindQueryBtn({
            type:'elock',
            bindClick:false,
            title:'${message("查询")}',
    		url:'/car/select_elock_car_list.jhtml?multi=2',
            callback:function(rows){
                if(rows.length>0){
                    for (var i = 0; i < rows.length;i++) {
                    	var $car_number = $("input.plateNum[value='"+rows[i].car_number+"']");
                    	var $berth = $("input.berth[value='"+rows[i].berth+"']");
    					if($car_number.length>0&&$berth.length>0){
    						$.message_alert('车牌号为【'+rows[i].car_number+'】且舱位为【'+rows[i].berth+'】的明细已添加');
    						return false;
    					}
                    }
                    for (var i = 0; i < rows.length;i++) {
						var row = rows[i];
						row.plate_num=row.car_number;
						row.position='';
						$tmGrid.addRow(row,null,1);
					}
                }
            }
        }); 
    })
	 
	var elockInItemIndex = 0;
	[#if terminalTaskItems!=null]
		var terminalTaskItems = ${terminalTaskItems};
	[#else]
		var terminalTaskItems = {};
	[/#if]
	 var cols = [
	     		{ title:'${message("鹤位")}', name:'position' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     			
	     			var html='<div class="nums-input ov">'+
	            	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
	            	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].position" value="'+val+'" minData="1" maxData="4" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
	            	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
	        	'</div>'+'<input type="hidden" name="terminalTaskItems['+elockInItemIndex+'].id" value="'+item.id+'" />';
	    			return html;
	     		}
	     		},
	         	{ title:'${message("车牌号")}', name:'plate_num' ,align:'center', renderer: function(val,item,rowIndex, obj){
	     			var	html = val+'<input type="hidden" name="terminalTaskItems['+elockInItemIndex+'].plateNum" class="text plateNum" value="'+val+'" btn-fun="clear"/>';
	     			return html;
	     		} },
	     		{ title:'${message("舱位")}', name:'berth' ,align:'center', renderer: function(val,item,rowIndex, obj){
	     			var	html = val+'<input type="hidden" name="terminalTaskItems['+elockInItemIndex+'].berth" class="text berth" value="'+val+'" btn-fun="clear"/>';
	     			return html;
	     		} },
	     		{ title:'${message("卸油机构")}', name:'to_sale_org_name' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     			var html='<span style="position:relative">'+
	     			'<input name="terminalTaskItems['+elockInItemIndex+'].toSaleOrg.id" class="text toSaleOrgId requireds" type="hidden" value="'+item.to_sale_org+'">'+
	     			'<input name="toSaleOrgName" class="text toSaleOrgName " maxlength="200" type="text" value="'+val+'" onkeyup="clearSelect(this)">'+
	     			'<input type="button" class="iconSearch " style="position: absolute;top: 0;right: 5px;" onclick="addtoSaleOrg(this,1)" value="" >'+
	     			'</span>';	
	     			return html;
	     		}
	     		},
	         	{ title:'${message("出发时间")}', name:'start_time' ,align:'center', width:130, renderer: function(val,item,rowIndex, obj){
	         		var str = val;
	    			var str1 = str.substring(0,19)
	         		return '<input  id="terminalTaskItems['+elockInItemIndex+'].startDate" value="'+str1+'" name="terminalTaskItems['+elockInItemIndex+'].startTime" class="text startTime requireds" value="" onClick="WdatePicker({dateFmt: \'yyyy-MM-dd HH:mm:ss\',startDate:\'%y-%M-%d %H:%m:%s\', maxDate: \'#F{$dp.$D(\\\''+'terminalTaskItems['+elockInItemIndex+'].endDate\\\')}\'});" type="text" btn-fun="clear"/>'
	         	}},
	         	{ title:'${message("预计到达时间")}', name:'end_time' ,align:'center', width:130, renderer: function(val,item,rowIndex, obj){
	         		var str = val;
	    			var str1 = str.substring(0,19)
	         		return '<input id="terminalTaskItems['+elockInItemIndex+'].endDate" value="'+str1+'" name="terminalTaskItems['+elockInItemIndex+'].endTime" class="text endTime requireds" value="" onClick="WdatePicker({dateFmt: \'yyyy-MM-dd HH:mm:ss\',startDate:\'%y-%M-%d %H:%m:%s\', minDate: \'#F{$dp.$D(\\\''+'terminalTaskItems['+elockInItemIndex+'].startDate\\\')}\'});" type="text" btn-fun="clear"/>'
	         	}},
	         	{ title:'${message("配送时长(分钟)")}', name:'duration' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	         		var html='<div class="nums-input ov">'+
	            	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
	            	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].duration" value="'+val+'" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
	            	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
	        	'</div>';
	    			return html;
	     		}
	     		},
	     		{ title:'${message("容量")}', name:'volume' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     			var html='<div class="nums-input ov">'+
	            	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
	            	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].volume" value="'+val+'" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
	            	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
	        	'</div>';
	    			return html;
	     		}
	     		},
	     		{ title:'${message("品名")}', name:'goods' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     			var	html = '<input type="text" name="terminalTaskItems['+elockInItemIndex+'].goods" class="text requireds" value="'+val+'" btn-fun="clear"/>';
	     			return html;
	     		}
	     		},
	     		{ title:'${message("数量")}', name:'quantity' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     			var html='<div class="nums-input ov">'+
	            	'<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  onMouseUp="editQty(this.nextSibling,event)">'+
	            	'<input type="text"  class="t requireds"  name="terminalTaskItems['+elockInItemIndex+'].quantity" value="'+val+'" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >'+
	            	'<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" onMouseUp="editQty(this.previousSibling,event)">'+
	        	'</div>';
	    			return html;
	     		}
	     		},
	         	{ title:'${message("备注")}', name:'memo' ,align:'center', width:110, renderer: function(val,item,rowIndex, obj){
	     				var	html = '<input type="text" name="terminalTaskItems['+elockInItemIndex+'].memo" class="text memo" value="'+val+'" btn-fun="clear"/>';
	     				return html;
	     			}
	     		},
	     		{ title:'${message("操作")}', align:'center', width:60, renderer:function(val,item){
	     			elockInItemIndex++;
	     		return '<a href="javascript:;" class="deleteElock btn-delete">删除</a>';
	     		}},
	     	];
	var $tmGrid=$('#table-elock').mmGrid({
		fullWidthRows:true,
		height:'auto',
        cols: cols,
        items:terminalTaskItems,
        checkCol: false,
        autoLoad: true,
    });
	
	[#if terminalMessageEvents!=null]
		var terminalMessageEvents = ${terminalMessageEvents};
	[#else]
		var terminalMessageEvents = {};
	[/#if]
	var ecols = [				
		    		{ title:'${message("终端设备编号")}', name:'terminal_num' ,align:'center',renderer:function(val,item,rowIndex){
		    			var valStr = '<input type="hidden" value="1_'+item.terminal_num+'"/>' + val;
		    			return valStr;
		    		}},
		    		{ title:'${message("事件信息")}', name:'event_message' ,align:'center', width:250},
		    		{ title:'${message("状态信息描述")}', name:'status_desc' ,align:'center', width:110},
		    		{ title:'${message("报警信息")}', name:'warning_message' ,align:'center', width:110},
		    		{ title:'${message("事件发生时间")}', name:'event_time' ,align:'center', width:120},
		    		{ title:'${message("处理人")}', name:'processor' ,align:'center'},
		    		{ title:'${message("车牌号")}', name:'car_number' ,align:'center'},
		    		{ title:'${message("锁编号")}', name:'elock_num' ,align:'center'},
		    		{ title:'${message("舱位")}', name:'position' ,align:'center',renderer:function(val,item,rowIndex){
						var berth=item.berth;
						var position=item.position;
						return (berth==null?'':berth)+','+(position==null?'':position);
					}},
		    		{ title:'${message("经度")}', name:'longitude' ,align:'center', },
		    		{ title:'${message("纬度")}', name:'latitude' ,align:'center', },
		    		{ title:'${message("基站定位数据")}', name:'jzdw' ,align:'center', },
		    		{ title:'${message("电压")}', name:'vol' ,align:'center', width:60},
		    		{ title:'${message("海拔高度")}', name:'altitude' ,align:'center', width:60},
		    		{ title:'${message("速度")}', name:'speed' ,align:'center', width:60},
		    		{ title:'${message("方向")}', name:'direction' ,align:'center', width:60},
		    		{ title:'${message("GPS时间")}', name:'gps_time' ,align:'center', width:120}
		    	];
		    	$emGrid=$('#table-terminal').mmGrid({
		    		fullWidthRows:true,
		            cols: ecols,
		            items:terminalMessageEvents,
		            checkCol: false,
		            height:'auto',
		            autoLoad: true,
		        });

	// 删除锁
    $deleteElock.live("click", function() {
        var index = $(this).closest("tr").index();
		$.message_confirm('您确定要删除吗？',function(){
			$tmGrid.removeRow(index);
		})
    });

	$("form").bindAttribute({
		isConfirm:true,
	    callback: function(resultMsg){
	        $.message_timer(resultMsg.type,resultMsg.content,1000,function(){
				location.reload(true);
			});
	    }
	 });
	
	// 表单验证
	$inputForm.validate({
		rules: {
			waybillNo: {
				required: true,
			},
			saleOrgId: {
				required:true
			}
		}
	});
	
	$.validator.addClassRules({
		requireds: {
			required: true
		}
	});
	
	//查询机构
	$("#selectSaleOrg").bindQueryBtn({
		type:'fromSaleOrg',
		title:'${message("查询机构")}',
		url:'/saleOrg/select_saleOrg.jhtml'
	});
	
	//查询机构
	$("#selectToSaleOrg").bindQueryBtn({
		type:'toSaleOrg',
		title:'${message("查询机构")}',
		url:'/saleOrg/select_saleOrg.jhtml'
	});


        $("#selectCar").bindQueryBtn({
            type:'elock',
            title:'${message("查询")}',
    		url:'/car/select_elock_car_list.jhtml?multi=2',
            callback:function(rows){
                if(rows.length>0){
					var row = rows[0];
					$("input[name='plateNum']").val(row.car_number);
					$("input[name='berth']").val(row.berth);
					$("span.berth").html(row.berth);
                }
            }
        }); 
	
});	
function addtoSaleOrg(e,flag){
	var $this= $(e);
	var thisnum= 's'+flag;
	var $tr=$this.closest("tr");
	$this.bindQueryBtn({
		type:'toSaleOrg',
		bindClick:false,
		title:'${message("查询组织")}',
		url:'/saleOrg/select_saleOrg.jhtml',
		callback:function(rows){
			if(rows.length>0){
					for (var i = 0; i < rows.length;i++) {
						$tr.find("input.toSaleOrgName").val(rows[i].name);
						$tr.find("input.toSaleOrgId").val(rows[i].id);
					}
				}
		}
	});
}

//完成
function complete(t){
	var str='您确定要完成该任务单吗';
	ajaxSubmit(t,{
		 url: 'complete.jhtml?ids=${terminalTask.id}',
		 method: "post",
		 isConfirm:true,
		 confirmText : str,
		 callback:function(resultMsg){
		 	$.message_timer(resultMsg.type,resultMsg.content,1000,function(){
				location.reload(true);
			});
		 }
	})
}
</script>
</head>
<body>
	<div class="pathh">
		&nbsp;${message("编辑任务单")}
	</div>
	<form id="inputForm" action="update.jhtml" method="post" type="ajax" validate-type="validate">
		<input type="hidden" name="id" value="${terminalTask.id}" />
		<div class="tabContent">
			<table class="input input-edit">
			<tr>
				<th>
					<span class="requiredField">*</span>${message("任务单流水号")}:
				</th>
				<td>
					${terminalTask.sn}
				</td>
				<th>
					<span class="requiredField">*</span>${message("任务单编号")}:
				</th>
				<td>
					<span class="error-msg"><input type="text" name="waybillNo" class="text " maxlength="20" value="${terminalTask.waybillNo }"  btn-fun="clear"/></span>
				</td>
				<th>
					${message("任务类别")}:
				</th>
				<td>
					<select id="categoryId" name="categoryId" class="text">
						[#list categorys as category]
						<option value="${category.id}" [#if terminalTask.category.id==category.id] selected[/#if]>${category.value}</option>
						[/#list]
					</select>
				</td>
				<th>
					<span class="requiredField">*</span>${message("提油机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="fromSaleOrgId" class="text fromSaleOrgId" btn-fun="clear" value="${ terminalTask.fromSaleOrg.id}"/>
					<input type="text" name="fromSaleOrgName" class="text requireds fromSaleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="${terminalTask.fromSaleOrg.name }" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectSaleOrg">
					</span>
				</td>
			</tr>
			<tr>
				<!-- <th>
					${message("开锁模式")}:
				</th>
				<td>
					<select id="unlockMode" name="unlockMode" class="text">
						<option value="0" [#if terminalTask.category==0] selected[/#if]>${message("M1自动模式")}</option>
						<option value="1" [#if terminalTask.category==1] selected[/#if]>${message("M2手动模式")}</option>
					</select>
				</td> -->
				<th>
					${message("状态")}:
				</th>
				<td>
					[#if terminalTask.status==0] ${message("未完成")}[#else]${message("已完成")}[/#if]
				</td>
				<th>
					${message("备注")}:
				</th>
				<td colspan="5">
					<span class="error-msg"><input type="text" name="memo" class="text " maxlength="20" value="${terminalTask.memo }"  btn-fun="clear"/></span>
				</td>
			</tr>
			
			<tr>
				<th>
					<span class="requiredField">*</span>${message("鹤位")}:
				</th>
				<td>
					<input type="text" name="position" class="text requireds" maxlength="20" value="${terminalTask.position }"  btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("车牌号")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="text" name="plateNum" class="text plateNum" maxlength="200" onkeyup="clearSelect(this)" value="${terminalTask.plateNum }" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectCar">
					</span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("舱位")}:
				</th>
				<td>
					<span class="berth">${terminalTask.berth }</span><input type="hidden" name="berth" class="text " maxlength="20" value="${terminalTask.berth }"  btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("卸油机构")}:
				</th>
				<td>
					<span class="search" style="position:relative">
					<input type="hidden" name="toSaleOrgId" class="text toSaleOrgId" btn-fun="clear" value="${terminalTask.toSaleOrg.id }"/>
					<input type="text" name="toSaleOrgName" class="text requireds toSaleOrgName" maxlength="200" onkeyup="clearSelect(this)" value="${terminalTask.toSaleOrg.name }" readOnly/>
					<input type="button" class="iconSearch" value="" id="selectToSaleOrg">
					</span>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("出发时间")}:
				</th>
				<td>
					<span class="error-msg">
					<input id="startTime" name="startTime" class="text startTime requireds" value="[#if terminalTask.startTime??]${terminalTask.startTime?string("yyyy-MM-dd HH:mm:ss")}[/#if]" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d %H:%m:%s', maxDate: '#F{$dp.$D(\'endTime\')}'});" type="text" btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("预计到达时间")}:
				</th>
				<td>
					<span class="error-msg">
					<input id="endTime" name="endTime" class="text requireds endTime" value="[#if terminalTask.endTime??]${terminalTask.endTime?string("yyyy-MM-dd HH:mm:ss")}[/#if]" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d %H:%m:%s', minDate: '#F{$dp.$D(\'startTime\')}'});" type="text" btn-fun="clear"/></span>
				</td>
				<th>
					<span class="requiredField">*</span>${message("配送时长(分钟)")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="duration" value="${terminalTask.duration }" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
				<th>
					<span class="requiredField">*</span>${message("容量")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="volume" value="${terminalTask.volume }" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
			</tr>
			<tr>
				<th>
					<span class="requiredField">*</span>${message("品名")}:
				</th>
				<td>
					<input type="text " name="goods" class="text requireds" maxlength="20" value="${terminalTask.goods }"  btn-fun="clear"/>
				</td>
				<th>
					<span class="requiredField">*</span>${message("数量")}:
				</th>
				<td>
					<div class="nums-input ov">
						<input type="button" class="b decrease" value="-"  onMouseDown ="decrease(this,event)"  >
						<input type="text"  class="t requireds"  name="quantity" value="${terminalTask.quantity }" minData="1" oninput="editQty(this,event)" onpropertychange="editQty(this,event)" >
						<input type="button" value="+" class="b increase"  onMouseDown ="increase(this,event)" >
					</div>
				</td>
				<th></th><td></td>
				<th></th><td></td>
			</tr>
			
			<!-- <tr class="partsShow border-L3">
				<th>
					${message("任务单明细")}:
				</th>
				<td colspan="7">
					<a href="javascript:;" id="addElock" class="button">${message("选择舱位")}</a>
				</td>
				</tr>
				<tr class="border-L3">
            	<td colspan="8">
            		<div>
						<table id="table-elock"></table>
					</div>
            	</td>
            	</tr> -->
            	<tr class="partsShow border-L2">
					<th>
						${message("事件信息")}:
					</th>
					<td colspan="7">
					</td>
				</tr>
            	<tr class="border-L2">
            	<td colspan="8">
            		<div>
						<table id="table-terminal"></table>
					</div>
            	</td>
            	</tr>
		</table>
		</div>
		<div class="fixed-top">
			<a href="add.jhtml" class="iconButton" id="addButton">
				<span class="addIcon">&nbsp;</span>${message("1001")}
			</a>
			[#if terminalTask.status==0]
			<input type="submit" id="submit_button" class="button sureButton" value="${message("1013")}" />
			<a href="javascript:void(0);" class="button sureButton" onclick="complete(this)">完成</a>
			[/#if]
			<input type="button" onclick="location.reload(true);" class="button resetButton ml15" value="${message("刷新")}">
		</div>
	</form>
</body>
</html>